package com.ynet.middleground.riskmanage.filter;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

/**
 * 项目名：ifp-contract <br>
 * 包名：com.ynet.middleground.contract.filter <br>
 * 类名：SpecialLogFilter <br>
 * 描述： 过滤特殊日志，指定 loggerName 规则的日志不发送至 logstash，适用于大报文（文件流等）
 * 
 * @author liwq
 * @create 2022-09-15 09:28
 */
public class SpecialLogFilter extends Filter<ILoggingEvent> {

    /**
     * 不发送至 logstash 的日志名称前缀
     */
    public static final String FILTER_FOR_LOGSTASH_PREFIX = "filter_for_logstash_";

    /**
     * loggerName 为 FILTER_FOR_LOGSTASH_PREFIX 前缀的日志过滤
     * 
     */
    @Override
    public FilterReply decide(ILoggingEvent iLoggingEvent) {
        String loggerName = iLoggingEvent.getLoggerName();
        if (loggerName.startsWith(FILTER_FOR_LOGSTASH_PREFIX)) {
            return FilterReply.DENY;
        }
        return FilterReply.NEUTRAL;
    }

}
